<!DOCTYPE html>
<html lang="zh" xmlns:th="https://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('访问日志列表')"/>
</head>
<body class="gray-bg">

<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="operlog-form">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>访问模块： </label><input type="text" name="title"/>
                        </li>
                        <li class="select-time">
                            <label>访问时间： </label>
                            <input type="text" class="time-input" id="startTime" placeholder="开始时间"
                                   name="params[beginTime]"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间"
                                   name="params[endTime]"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-danger btn-del multiple disabled" onclick="$.operate.removeAll()">
                <i class="fa fa-trash"></i> 删除
            </a>
            <a class="btn btn-danger" onclick="$.operate.clean()">
                <i class="fa fa-trash"></i> 清空
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()">
                <i class="fa fa-download"></i> 导出
            </a>
            <a class="btn btn-info" onclick="javascript:blacklist()">
                <i class="fa fa-list"></i> 黑名单
            </a>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>

<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var datas = [[${@dict.getType('sys_oper_type')}]];
    var prefix = ctx + "log/visitLog";

    $(function () {
        var options = {
            url: prefix + "/list",
            cleanUrl: prefix + "/clean",
            detailUrl: prefix + "/detail/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            sortName: "create_time",
            sortOrder: "desc",
            modalName: "访问记录",
            escape: true,
            columns: [{
                field: 'state',
                checkbox: true
            }, {
                field: 'visitId',
                title: '访问ID'
            }, {
                field: 'title',
                title: '请求模块',
                sortable: true
            }, {
                field: 'os',
                title: '操作系统',
            }, {
                field: 'browser',
                title: '浏览器'
            }, {
                field: 'ipAddr',
                title: '主机',
                sortable: true
            }, {
                field: 'location',
                title: '地点'
            }, {
                field: 'createTime',
                title: '访问时间',
                sortable: true
            }, {
                field: 'status',
                title: '状态',
                align: 'center',
                formatter: function (value, row, index) {
                    if (value == 1) {
                        return '<span class="badge badge-primary">成功</span>';
                    } else if (value == 0) {
                        return '<span class="badge badge-danger">异常</span>';
                    }
                }
            }, {
                title: '操作',
                align: 'center',
                formatter: function (value, row, index) {
                    var actions = [];
                    actions.push('<a class="btn btn-info btn-xs ' + '" href="javascript:void(0)" onclick="$.operate.detail(\'' + row.visitId + '\')"><i class="fa fa-search"></i>详细</a> ');
                    actions.push('<a class="btn btn-danger btn-xs ' + '" href="javascript:void(0)" onclick="addBlacklist(\'' + row.ipAddr + '\')"><i class="fa fa-exclamation-triangle"></i>加入黑名单</a> ');
                    return actions.join('');
                }
            }]
        };
        $.table.init(options);
    });

    function addBlacklist(ipAddr) {
        $.modal.confirm("确认将此IP地址 [" + ipAddr + "]移入黑名单？", function () {
            $.operate.post("/monitor/blacklist/addBlacklist", {"ipAddr": ipAddr});
        })
    }

    function blacklist() {
        var url = ctx + 'monitor/blacklist';
        createMenuItem(url, "黑名单");
    }
</script>
</body>
</html>